package org.example.day07;

/**
 * 第三章节3.1.12: interrupt方法遇到wait方法
 *      注意：当线程调用wait方法后，等待notify的过程中，如果再对该线程对象执行interrupt()方法时，会出现InterruptedException异常
 */
public class MyThread10 {
    public void testMethod(Object lock){
        try {
            synchronized (lock){
                System.out.println("begin wait");
                lock.wait();
                System.out.println("end wait");
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
            System.out.println("出现异常*******");
        }
    }

    public static void main(String[] args) {
        try {
            Object lock = new Object();
            Thread10A ta = new Thread10A(lock);
            ta.start();
            Thread.sleep(5000);
            ta.interrupt();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

class Thread10A extends Thread{
    private Object lock;

    public Thread10A(Object lock) {
        this.lock = lock;
    }

    @Override
    public void run() {
        MyThread10 m10 = new MyThread10();
        m10.testMethod(lock);
    }
}